package org.meichao.config;

import org.meichao.config.vo.DataSourceEnum;

public class DataSourceContextHolder {

    private static final ThreadLocal<String> local = new ThreadLocal<>();

    public static ThreadLocal<String> getLocal(){
        return local;
    }

    /**
     * 切换到读库
     */
    public static void switch2Read(){
        local.set(DataSourceEnum.read.getType());
    }
    /**
     * 切换到写库
     */
    public static void switch2Write(){
        local.set(DataSourceEnum.write.getType());
    }

    /**
     * 返回当前线程的此线程局部变量的副本中的值
     */
    public static String getDataSourceType(){
        return local.get();
    }

}
